package com.lv.controller;

import com.lv.data.Result;
import com.lv.pojo.TbBrand;
import com.lv.service.BrandService;

import com.lv.util.Page;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("brand")
public class BrandController {

    @DubboReference   //远程调用注解
    private BrandService bs;

    @RequestMapping("brandList")
    @ResponseBody
    public Page brandList(@RequestParam(defaultValue = "1")Integer pageNum,
                                   @RequestParam(defaultValue = "5") Integer pageSize){
        Page<TbBrand> pb = bs.brandList(pageNum,pageSize);
        return pb;
    }
    //增加
    @RequestMapping("add")
    @ResponseBody
    public Integer add(TbBrand b) {
        Integer i=  bs.add(b);
        return i;
    }
    //回显
    @RequestMapping("toupdate/{id}")
    @ResponseBody
    public TbBrand toupdate(@PathVariable("id") Long id){
        TbBrand toupdate = bs.toupdate(id);
        return toupdate;
    }

    //修改
    @RequestMapping("update")
    @ResponseBody
    public Integer update(TbBrand b){
        Integer i = bs.update(b);
        return i;
    }

    //删除
    @RequestMapping("delBrands")
    @ResponseBody
    public Result delBrands(@RequestParam(value = "ids") List<Long> ids){
        try {
            bs.delBrands(ids);
            return Result.OK();
        } catch (Exception e) {
            e.printStackTrace();//打印失败原因
            return Result.ER();
        }
    }

    //查询全部
    @RequestMapping("slelectAll")
    @ResponseBody
    public List<TbBrand> selectAll(){
        return bs.selectAll();
    }




/*            页面跳转               */
    // brand页面
    @RequestMapping("tobrand")
    public String toBrand() {
        return "admin/brand";
    }


}
